import 'package:boss/ui/page/reportForm/order/page/orderDetail/provider/order_detail_provider.dart';
import 'package:boss/ui/page/reportForm/order/page/orderDetail/widget/order_detail_browser.dart';
import 'package:boss/ui/page/storeEvaluate/storeEvaluate.dart';
import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:boss/ui/widget/label_button.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:router/annotation.dart';

@RouterConfig(OrderDetailPage.pageName)
class OrderDetailPage extends StatefulWidget {
  static const pageName = '/orderDetailPage';

  @Autowired()
  final String unionOrderId;

  @Autowired()
  final String startDate;

  @Autowired()
  final String endDate;

  const OrderDetailPage({Key key, this.unionOrderId, this.startDate, this.endDate}) : super(key: key);

  @override
  _OrderDetailPageState createState() => _OrderDetailPageState('订单详情');
}

class _OrderDetailPageState extends BaseState<OrderDetailPage> {
  _OrderDetailPageState(String pageName) : super(pageName);

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(
          create: (context) => OrderDetailProvider(unionOrderId: widget.unionOrderId),
        )
      ],
      child: Scaffold(
        appBar: CenterTitleAppBar(
          title: '订单详情',
          actions: <Widget>[
            LabelButton(
              title: '查看评论',
              onTap: () {
                if (widget.unionOrderId != null && widget.unionOrderId != '') {
                  Navigator.pushNamed(context, StoreEvaluate.pageName, arguments: {
                    "unionOrderId": widget.unionOrderId,
                    "beginTime": widget.startDate.toString().substring(0, 10),
                    "endTime": widget.endDate.toString().substring(0, 10),
                  });
                } else {
                  toast("无订单ID");
                }
              },
            ),
          ],
        ),
        body: OrderDetailBrowser(),
      ),
    );
  }
}
